package com.rupyi.service.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.mbp.page.PageQuery;
import com.ruoyi.common.core.mbp.page.TableDataInfo;
import com.rupyi.service.domain.vo.ExampleVo;
import com.rupyi.service.service.ExampleService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/example")
@RequiredArgsConstructor
public class ExampleController {

    private final ExampleService exampleService;

    @PostMapping("/retrieveList")
    public TableDataInfo<ExampleVo> retrieveList(@RequestBody ExampleVo entity) {

        PageQuery pageQuery = new PageQuery();
        pageQuery.setPageNum(entity.getPageNum());
        pageQuery.setPageSize(entity.getPageSize());

        return exampleService.retrieveList(entity, pageQuery);
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @GetMapping("/retrieveById")
    public R<ExampleVo> retrieveById(@RequestParam("id") String id) {
        ExampleVo example = exampleService.retrieveVoById(id);
        return R.ok(example);
    }

    @PostMapping("/create")
    public R<Integer> create(@RequestBody ExampleVo entity) {
        return R.ok(exampleService.create(entity));
    }

}
